package team.paimengshop.server_database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class PaiMengShopDatabase
{
    private static Connection cn = null;
    //连接数据库的URL，用户名和密码
    private static final String url = "jdbc:mysql://localhost:3306/paimengshopdatabase";
    private static final String username = "root";
    private static final String password = "148432";

    //创建一个获取数据库连接的方法，返回数据库连接对象
    public static Connection getConnection()
    {
        try
        {
            //加载驱动类
            Class.forName("com.mysql.cj.jdbc.Driver");  //括号里的为包名
            cn = DriverManager.getConnection(url, username, password);
        }
        catch (ClassNotFoundException | SQLException e)
        {
            e.printStackTrace();
        }
        return cn;
    }
}
